package com.team.controller;

import com.team.pojo.BackendUser;
import com.team.pojo.DevUser;
import com.team.service.BackendUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/")
public class BackendUserController {
 @Autowired
 private BackendUserService backendUserService;
 @RequestMapping("blogin")
 public String blogin(String username, String password, HttpSession session, Model model){
  BackendUser backendUser=backendUserService.login(username,password);
  if (backendUser==null){  //登入失败
   model.addAttribute("error","用户名或密码错误");
   return "backendlogin";
  }else {
   //使用session保存用户信息
   session.setAttribute("backendInfo", backendUser);
   session.setMaxInactiveInterval(10 * 60);//20分钟有效
   return "backend/main";
  }
 }
 @RequestMapping("blogout")  //退出后台登录
 public String blogout(HttpSession session){
  //清除session
  session.removeAttribute("backendInfo");
  return "backendlogin";
 }
}
